/*
   Copyright (c) 2011 Mizar Tools Contributors (mizartools.org)

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
/*  Contributors :
 *	2011-02-04 Marco Riccardi - initial implementation
 *
 */
package org.mizartools.system;

import org.mizartools.utility.SystemHost;

public class Error {

	private int id;
	private String errorId;
	private String errorMessage;
	
	public Error(int id, String errorId, String errorMessage){
		this.id = id;
		this.errorId = errorId;
		this.errorMessage = errorMessage;
	}
	
	public int getId() {
		return id;
	}

	public String getErrorMessage() {
		return errorMessage;
	}

	public String toRecordInFile(){
		String ret = SystemHost.lineTerminator;
		StringBuffer sb = new StringBuffer("");
		sb.append(errorId);
		sb.append(ret);
		sb.append(errorMessage);
		sb.append(ret);
		return sb.toString();
	}
	
	@Override
	public String toString(){
		StringBuffer sb = new StringBuffer("");
		sb.append("#");
		sb.append(id);
		sb.append(" ");
		sb.append(errorMessage);
		return sb.toString();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((errorId == null) ? 0 : errorId.hashCode());
		result = prime * result
				+ ((errorMessage == null) ? 0 : errorMessage.hashCode());
		result = prime * result + id;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Error other = (Error) obj;
		if (errorId == null) {
			if (other.errorId != null)
				return false;
		} else if (!errorId.equals(other.errorId))
			return false;
		if (errorMessage == null) {
			if (other.errorMessage != null)
				return false;
		} else if (!errorMessage.equals(other.errorMessage))
			return false;
		if (id != other.id)
			return false;
		return true;
	}
	
}
